﻿using K9Nano.Caching;
using K9Nano.Dependency;

namespace K9Nano.Captcha;

internal class MemoryCaptchaStore(ITypedCache<CaptchaRecord> cache) : ICaptchaStore, ISingletonDependency
{
    public string? Get(string requestId)
    {
        // 从缓存中获取验证码
        var captcha = cache.Get(requestId);
        return captcha?.Code;
    }

    public void Remove(string requestId)
    {
        cache.Remove(requestId);
    }

    public void Save(string requestId, string code, TimeSpan expire)
    {
        cache.Add(requestId, new CaptchaRecord(code, DateTime.Now.Add(expire)), null, expire);
    }
}
